﻿using System;
using System.Collections.Generic;
using SimpleFS.Core;
using SimpleFS.Core.Implementations;

namespace SimpleFS.Services.Compression
{
    public class Directory : AbstractDirectory
    {
        protected ICompressionServiceProvider provider;

        public Directory(IDirectory internalObject, ICompressionServiceProvider provider) : base(internalObject)
        {
            this.provider = provider;
        }

        #region IDirectory Members

        public override IDirectory[] Directories
        {
            get
            {
                IDirectory[] directories = base.internalObject.Directories;
                Directory[] newDirectories = new Directory[directories.Length];

                for (int index = 0; index < directories.Length; index++)
                {
                    newDirectories[index] = new Directory(
                        directories[index], this.provider);
                }

                return newDirectories;
            }
        }

        public override IFile[] Files
        {
            get
            {
                IFile[] files = base.internalObject.Files;
                File[] newFiles = new File[files.Length];

                for (int index = 0; index < files.Length; index++)
                {
                    newFiles[index] = new File(
                        files[index], this.provider);
                }

                return newFiles;
            }
        }

        public override IFile AddFile(string fileName)
        {
            return new File(
                base.internalObject.AddFile(fileName),
                this.provider);
        }

        public override IDirectory AddDirectory(string directoryName)
        {
            return new Directory(
                base.internalObject.AddDirectory(directoryName), this.provider);
        }
        
        #endregion
    }
}
